﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using OA.DBUtility;
using OA.Model;
using System.Collections.Generic;

namespace OA.Manager
{
	/// <summary>
	/// 数据访问类:Training
	/// </summary>
	public partial class TrainingManager
	{
		private SqlService<TrainingInfo> _sqlService = null;

        public TrainingManager()
		{
            _sqlService = new SqlService<TrainingInfo>();
        }

		#region  Method		

        /// <summary>
        /// 插入新记录
        /// </summary>
        /// <param name="trainingInfo"></param>
        /// <returns></returns>
        public int  InsertTrainingInfo(TrainingInfo trainingInfo)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4),
					new SqlParameter("@StartTime", SqlDbType.DateTime),
					new SqlParameter("@FinishedTime", SqlDbType.DateTime),
					new SqlParameter("@TrainingInstitutions", SqlDbType.NVarChar,50),
					new SqlParameter("@TrainingCourse", SqlDbType.NVarChar,50),
					new SqlParameter("@Certification", SqlDbType.NVarChar,50),
					new SqlParameter("@TrainingFee", SqlDbType.Money,8),
					new SqlParameter("@ClassHour", SqlDbType.Int,4),
					new SqlParameter("@Lecturer", SqlDbType.NVarChar,50),
                    new SqlParameter("@TrainingType", SqlDbType.NVarChar,50),
                    new SqlParameter("@CertificationNo", SqlDbType.NVarChar,50)};

            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = trainingInfo.StartTime;
            parameters[2].Value = trainingInfo.FinishedTime;
            parameters[3].Value = trainingInfo.TrainingInstitutions;
            parameters[4].Value = trainingInfo.TrainingCourse;
            parameters[5].Value = trainingInfo.Certification;
            parameters[6].Value = trainingInfo.TrainingFee;
            parameters[7].Value = trainingInfo.ClassHour;
            parameters[8].Value = trainingInfo.Lecturer;
            parameters[9].Value = trainingInfo.TrainingType;
            parameters[10].Value = trainingInfo.CertificationNo;
            _sqlService.ExecuteNonQueryByProcedure("Proc_Training", parameters);
            return (int)parameters[0].Value;
        }

        /// <summary>
        /// 根据打印任务ID获得打印任务信息
        /// </summary>
        /// <param name="taskID"></param>
        /// <returns></returns>
        public TrainingInfo GetTrainingInfoByID(int ID)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("ID", ID);
            return _sqlService.GetSingleByFields(dic, null);
        }

        /// <summary>
        /// 判断该打印任务是否存在
        /// </summary>
        /// <param name="trainingInfo"></param>
        /// <returns></returns>
        public bool IsExistTrainingInfo(TrainingInfo trainingInfo)
        {
            return _sqlService.IsExist(trainingInfo);
        }

        /// <summary>
        /// 根据指定的字段更新，字段名是数据库中对应的名称
        /// </summary>
        /// <param name="trainingInfo"></param>
        /// <param name="needUpdateFields"></param>
        /// <returns></returns>
        public bool UpdateTrainingInfo(TrainingInfo trainingInfo, List<string> needUpdateFields)
        {
            return _sqlService.UpdateByFields(trainingInfo, needUpdateFields);
        }

        /// <summary>
        /// 删除该检查任务
        /// </summary>
        /// <param name="trainingInfo"></param>
        /// <returns></returns>
        public bool DeleteTrainingInfo(TrainingInfo trainingInfo)
        {
            return _sqlService.DeleteEntity(trainingInfo);
        }
		
		#endregion  Method
	}
}

